package com.ruoyi.system.service.impl;

import java.util.HashMap;
import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AttachFileMapper;
import com.ruoyi.system.domain.AttachFile;
import com.ruoyi.system.service.IAttachFileService;

import javax.annotation.Resource;

/**
 * 附件Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-20
 */
@Service
public class AttachFileServiceImpl implements IAttachFileService 
{
    @Resource
    private AttachFileMapper attachFileMapper;

    /**
     * 查询附件
     * 
     * @param id 附件主键
     * @return 附件
     */
    @Override
    public AttachFile selectAttachFileById(Long id)
    {
        return attachFileMapper.selectAttachFileById(id);
    }

    /**
     * 查询附件列表
     * 
     * @param attachFile 附件
     * @return 附件
     */
    @Override
    public List<AttachFile> selectAttachFileList(AttachFile attachFile)
    {
        return attachFileMapper.selectAttachFileList(attachFile);
    }

    /**
     * 新增附件
     * 
     * @param attachFile 附件
     * @return 结果
     */
    @Override
    public int insertAttachFile(AttachFile attachFile)
    {
        attachFile.setCreateTime(DateUtils.getNowDate());
        return attachFileMapper.insertAttachFile(attachFile);
    }

    /**
     * 修改附件
     * 
     * @param attachFile 附件
     * @return 结果
     */
    @Override
    public int updateAttachFile(AttachFile attachFile)
    {
        attachFile.setUpdateTime(DateUtils.getNowDate());
        return attachFileMapper.updateAttachFile(attachFile);
    }

    /**
     * 批量删除附件
     * 
     * @param ids 需要删除的附件主键
     * @return 结果
     */
    @Override
    public int deleteAttachFileByIds(Long[] ids)
    {
        return attachFileMapper.deleteAttachFileByIds(ids);
    }

    /**
     * 删除附件信息
     * 
     * @param id 附件主键
     * @return 结果
     */
    @Override
    public int deleteAttachFileById(Long id)
    {
        return attachFileMapper.deleteAttachFileById(id);
    }

    @Override
    public AjaxResult getgAndcNames(){
        AjaxResult ajaxResult = new AjaxResult();
        try {
            List<HashMap<String, Object>> nameMap = attachFileMapper.getgAndcNames();
            ajaxResult.put(AjaxResult.DATA_TAG, nameMap);
            ajaxResult.put(AjaxResult.CODE_TAG, Constants.BUSINESS_SUCCESS);
            ajaxResult.put(AjaxResult.MSG_TAG, "查询成功！");
        }catch (Exception e){
            e.printStackTrace();
            ajaxResult.put(AjaxResult.CODE_TAG, Constants.BUSINESS_FAIL);
            ajaxResult.put(AjaxResult.MSG_TAG, "查询失败，请联系管理员！");
        }

        return ajaxResult;
    }
}
